package com.orange.mybatisplus;

import com.orange.mybatisplus.entity.User;
import com.orange.mybatisplus.mapper.UserMapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

/**
 * Description: 删除user操作测试
 */
@SpringBootTest
public class DeleteUser {

    @Autowired
    private UserMapper userMapper;

    //根据id删除记录
    @Test
    public void testDeleteById() {
        int result = userMapper.deleteById(1L);
        System.out.println(result);
    }

    //批量删除
    @Test
    public void testDeleteBatchIds() {
        int result = userMapper.deleteBatchIds(Arrays.asList(2, 3, 4));
        System.out.println(result);
    }

    //简单的条件查询删除
    @Test
    public void testDeleteByMap() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("name", "baijuyi");
        map.put("age", 110);
        int result = userMapper.deleteByMap(map);
        System.out.println(result);
    }

    //测试 逻辑删除
    @Test
    public void testLogicDelete() {
        int result = userMapper.deleteById(5L);
        System.out.println(result);
    }

    //测试 逻辑删除后的查询：不包括被逻辑删除的记录
    @Test
    public void testLogicDeleteSelect() {
        User user = new User();
        List<User> users = userMapper.selectList(null);
        users.forEach(System.out::println);
    }

}
